package org.budo.xml;

import java.util.Map;

import lombok.Getter;
import lombok.Setter;

/**
 * @author lmw
 */
@Getter
@Setter
public class XmlObjectWrapper implements XmlObject {
    private XmlObject xmlObject;

    private XmlObject xmlObject() {
        if (null != this.xmlObject) {
            return this.xmlObject;
        }

        return this.xmlObject = this.getXmlObject();
    }

    @Override
    public String getNodeName() {
        if (null == this.xmlObject()) {
            return null;
        }

        return this.xmlObject().getNodeName();
    }

    @Override
    public String getTextContent() {
        if (null == this.xmlObject()) {
            return null;
        }

        return this.xmlObject().getTextContent();
    }

    @Override
    public XmlObject[] getChildNodeArray() {
        if (null == this.xmlObject()) {
            return null;
        }

        return this.xmlObject().getChildNodeArray();
    }

    @Override
    public XmlObject[] getChildNodeArrayByName(String nodeName) {
        if (null == this.xmlObject()) {
            return null;
        }

        return this.xmlObject().getChildNodeArrayByName(nodeName);
    }

    @Override
    public XmlObject getChildNodeByName(String nodeName) {
        if (null == this.xmlObject()) {
            return null;
        }

        return this.xmlObject().getChildNodeByName(nodeName);
    }

    @Override
    public String getChildNodeTextContentByName(String nodeName) {
        if (null == this.xmlObject()) {
            return null;
        }

        return this.xmlObject().getChildNodeTextContentByName(nodeName);
    }

    @Override
    public XmlObject removeChildNodeByName(String nodeName) {
        if (null == this.xmlObject()) {
            return null;
        }

        return this.xmlObject().removeChildNodeByName(nodeName);
    }

    @Override
    public Map<String, String> getAttributeMap() {
        if (null == this.xmlObject()) {
            return null;
        }

        return this.xmlObject().getAttributeMap();
    }

    @Override
    public String getAttributeValue(String attributeName) {
        if (null == this.xmlObject()) {
            return null;
        }

        return this.xmlObject().getAttributeValue(attributeName);
    }

    @Override
    public Integer getAttributeValueInteger(String attributeName) {
        if (null == this.xmlObject()) {
            return null;
        }

        return this.xmlObject().getAttributeValueInteger(attributeName);
    }

    @Override
    public String getAttributeValue(String attributeName, String defaultValue) {
        if (null == this.xmlObject()) {
            return null;
        }

        return this.xmlObject().getAttributeValue(attributeName, defaultValue);
    }

    @Override
    public Integer getAttributeValueInteger(String attributeName, Integer defaultValue) {
        if (null == this.xmlObject()) {
            return null;
        }

        return this.xmlObject().getAttributeValueInteger(attributeName, defaultValue);
    }

    @Override
    public String toString() {
        if (null == this.xmlObject()) {
            return super.toString();
        }

        return this.xmlObject().toString();
    }
}